/**只要添加这段代码，就会有全选的功能*/
$(document).ready(function(){
	init();
});

function init(){
	$("#uploader").pluploadQueue({
		// General settings
		runtimes : 'html5,flash,silverlight',
		url : ctp + '/uploadController/uploadFile.shtml',
		max_file_size : '1gb',
		unique_names : true,
		multiple_queues : true,
		file_data_name : 'multipartFile',
		multipart : true,
		chunk_size: '10mb',
		// Specify what files to browse for
		/*filters : [
			{title : "图片、视频、音频文件", extensions : "ts,mpg,mpeg,avi,mp4,mkv,m2t,flv,mov,wmv,rmvb,vob,3gp,swf,mp3,bmp,gif,png,jpeg,jpg"}
		],*/
		//设置传到后台的默认参数
		multipart_params: { 'screenType': '0', 'adType': '0', 'isMaterial': '0','fileName':'' },
		max_retries: 3,
		// Flash settings
		flash_swf_url : ctp + '/pages/system/upload/js/plupload/js/Moxie.swf',
		// Silverlight settings
		silverlight_xap_url : ctp + '/pages/system/upload/js/plupload/js/Moxie.xap',
	});

	var uploader = $('#uploader').pluploadQueue();
	
	uploader.bind('ChunkUploaded', function(up, file, response) {
		response = jQuery.parseJSON(response.response);
		if(response != null && typeof(response.error)!="undefined"){
			if (response.error.code){
				file.status = plupload.FAILED;
				uploader.trigger('Error', {
					code : response.error.code,
		            message : response.error.message,
		            details : response.details,
		            file : file
				});
				uploader.stop();
			}
		}
	});
	
	uploader.bind('FileUploaded', function(up, file, response) {
		response = jQuery.parseJSON(response.response);
		if(response != null && typeof(response.error)!="undefined"){
			if (response.error.code){
				file.status = plupload.FAILED;
				uploader.trigger('Error', {
					code : response.error.code,
		            message : response.error.message,
		            details : response.details,
		            file : file
				});
				uploader.stop();
			}
			mediaAlert("",response.error.message);
			uploader.stop();
			return ;
		}
	});
	
	uploader.bind('FilesAdded', function(uploader, files) {
		var _files = uploader.files;
		var b = 0;
		for(var i=0;i<_files.length;i++){
			if(_files[i].status != plupload.DONE){
				b ++;
			}
		}
		if(b > 10){
			mediaAlert("","自动添加队列长度为10个文件！");
			uploader.splice(_files.length-b+10,b-10);	
		}
	});
	
	var adType="";
	uploader.bind('BeforeUpload', function(up, file) {
		//验证：点播视频文件类型必须是视频类型文件
	/*	var typeOfVideo="ts,mpg,mpeg,avi,mp4,mkv,m2t,flv,mov,wmv,rmvb,vob,3gp,swf";
		var type=file.name.split(".")[1];
		if(adType=='2'){
			if(type){
				if(typeOfVideo.indexOf(type)<0){
					mediaAlert("提示","点播视频文件类型必须是视频类型文件！");
					uploader.stop();
					return false;
				}
			}
		}*/
		//设置参数传到后台
		uploader.settings.multipart_params.fileName = file.name;
		closeLoading();
	});

	uploader.bind('UploadComplete', function(uploader, files) {
		setTimeout(function(){
			//window.opener.searchData();
			var r=confirm("上传完成，是否继续上传？");
			if (r==true){
				
			}else{
				history.back();
			}
		},1000);
		
	});
	
	$(".popClose").click(function(){
		uploader.stop();
	});
}
function back(){
	history.back();
}

